package servlet;

import dao.UserDao;
import dao.impl.UserDaoImpl;
import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/register.do")
public class registerServlet extends HttpServlet {
//    这里究竟用不用static好呢？不用在new此类时也能初始化
    private UserDao userDao=new UserDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String user_type=req.getParameter("user_type");
        String username=req.getParameter("username");
        String pwd=req.getParameter("pwd");
        String pho=req.getParameter("pho");
        switch (user_type){
//            顾客
            case "0":
                User user=new User(null,username,pwd,pho);
                int flag=userDao.addUser(user);
                System.out.println("insert User:"+flag);
                if (flag==1)
                    resp.getWriter().print("<script>alert('register Success');window.location.href='/DataBaseProject_war_exploded/login.html'</script>");
                else
                    resp.getWriter().print("<script>alert('register Fail');window.location.href='/DataBaseProject_war_exploded/register.html'</script>");
                break;
//            骑手
            case "1":

                break;
//            商家
            case "2":

                break;

//            管理员
            case "3":
                break;
        }
    }
}
